package com.ljz.service.impl;

import com.ljz.dao.UserDao;
import com.ljz.entity.User;
import com.ljz.service.UserService;
import com.ljz.utils.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements UserService {
    @Override
    public boolean login(User user) {
        SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
        UserDao userDao = sqlSession.getMapper(UserDao.class);
        User user1 = userDao.login(user);
        if (user1 != null) {
            sqlSession.close();
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int addUser(User user) {
        SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
        UserDao userDao = sqlSession.getMapper(UserDao.class);
        int num = userDao.addUser(user);
        sqlSession.commit();
        sqlSession.close();
        return num;
    }

    @Override
    public User findByUid(Integer uid) {
        return null;
    }

    @Override
    public int ckeckName(String name) {
        return 0;
    }
}
